// 2025/11/7
// 跳跃游戏2

class Solution {
public:
    int jump(vector<int>& nums) {
        int cur = 0, n = nums.size(), ans = 0;
        while(cur < n)
        {
            int end = cur + nums[cur], next = cur;
            if(end >= n - 1)
                return cur == n - 1 ? ans : ans + 1;
            for(int i = cur + 1; i < n && i <= end; i++)
            {
                if(i + nums[i] > next + nums[next])
                {
                    next = i;
                }
            }
            if(next == cur)
                return -1;
            cur = next;
            ans++;
        }
        return -1;
    }
};